package com.chen.config;


import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;

import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

//编写了Mybatis-Plus的配置类
// 我们就可以让配置类扫描mapper接口包，不用使用主启动类进行扫描
@MapperScan("com.chen.mapper")
@EnableTransactionManagement  //开启事务控制管理
@Configuration
public class MybatisPlusConfig {

    //注册乐观锁的bean，也可以自定义
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //乐观锁配置拦截器
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        //分页插件配置拦截器
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
        return interceptor;
    }


    //逻辑删除配置 不需要

    //性能分析插件，暂不需要


}
